import { createStore, Module } from 'vuex';
import { State } from './interface';

interface FilesType {
  [key: string]: Module<any, State>
}
const files: { [key: string]: FilesType } = import.meta.globEager(
  "./modules/*.ts"
);
const modules: FilesType = {}
Object.keys(files).forEach((key) => {
  const nameMatch = key.match(/^\.\/modules\/(.+)\.ts/);
  if (!nameMatch) return;
  modules[nameMatch[1]] = files[key].default;
  modules[nameMatch[1]]['namespaced'] = true
});
const store = createStore({
  modules
})

export default store